import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:pornhub_app/components/image_view.dart';
import 'package:pornhub_app/components/text_view.dart';
import 'package:pornhub_app/utils/color.dart';
import 'package:pornhub_app/utils/utils.dart';

import '../../../generate/app_image_path.dart';
import '../../../model/community/community_date_model.dart';

class MineReleaseCommunityCell extends StatelessWidget {
  final CommunityDateModel model;
  final int status; //1-已发布 2-待审核 3-未通过

  const MineReleaseCommunityCell(
      {super.key, required this.model, required this.status});

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      width: double.infinity,
      height: 104.w,
      child: Flex(
        direction: Axis.horizontal,
        children: [
          Stack(
            children: [
              _buildCover(),
              if (status > 1) _buidCheckView(),
            ],
          ),
          Expanded(
            child: _buildTxtContent(),
          ),
        ],
      ),
    );
  }

  _buildCover() {
    return ImageView(
      src: getPicture() ?? '',
      width: 182.w,
      height: 104.w,
      borderRadius: BorderRadius.circular(4),
    );
  }

  String? getPicture() {
    model.coverImg ??= [];
    if (model.coverImg != null && model.coverImg!.isNotEmpty) {
      return model.coverImg![0];
    }
  }

  _buildTxtContent() {
    return Container(
      padding: EdgeInsets.only(left: 6.w, right: 10.w, bottom: 5.w, top: 10.w),
      height: 104.w,
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Expanded(
            child: TextView(
              text: model.title ?? '',
              fontSize: 12.w,
              color: Colors.white,
            ),
          ),
          TextView(
            text: '${Utils.dateFmt(model.checkAt!)}发布',
            fontSize: 9.w,
            color: COLOR.color_A4A4B2,
          ),
          if (status == 3)
            Image.asset(AppImagePath.mine_img_mine_check_delete,
                width: 14.w, height: 14.w),
        ],
      ),
    );
  }

  //审核时的view
  _buidCheckView() {
    return Positioned.fill(
      child: Container(
        width: 182.w,
        height: 104.w,
        decoration: BoxDecoration(
          color: Colors.black54,
          borderRadius: BorderRadius.circular(4),
        ),
        child: status == 2 ? _checkViewTwo() : _checkViewThree(),
      ),
    );
  }

  //审核中
  _checkViewTwo() {
    return Stack(
      children: [
        Positioned(
            width: 182.w,
            height: 104.w,
            top: 30.w,
            child: Column(
              children: [
                Image.asset(AppImagePath.mine_img_mine_check_bg,
                    width: 17.w, height: 17.w),
                TextView(text: '审核中', fontSize: 12.w, color: Colors.white),
              ],
            )),
      ],
    );
  }

  //未通过
  _checkViewThree() {
    return Stack(
      children: [
        Positioned(
            bottom: 5.w,
            child: Expanded(
                child: TextView(
                    text: model.notPass ?? '',
                    fontSize: 10.w,
                    color: Colors.white))),
      ],
    );
  }
}
